//
//  M_PhotoDetailViewController.m
//  Model
//
//  Created by apple on 2018/7/11.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "M_PhotoDetailViewController.h"
#import "M_PhotoMineDetailViewController.h"//个人详情
#import "M_PhotoHuDongViewController.h"//互动
#import <UShareUI/UShareUI.h>

@interface M_PhotoDetailViewController ()<UIScrollViewDelegate,UITextViewDelegate>

{
    UIView *grayView;//
    
}

@property(nonatomic,strong) UIScrollView *sxssScrollView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UIView *headrView;//返回view
@property (nonatomic, strong) UIView *footView;//评论view
@property (nonatomic, strong) UILabel *numLab;//显示数量
@property (nonatomic, strong) UIButton *headBtn;//头像
@property (nonatomic, strong) UIButton *collectionBtn;//收藏
@property (nonatomic, strong) UIButton *commentBtn;//互动
@property (nonatomic, strong) UITextView *commentTF;//评论
@property (nonatomic, strong) UIButton *faSongBtn;//发送
@property (nonatomic, strong) UIView *commentView;
@property (nonatomic, strong) UIButton *fenXiangBtn;//分享
@property (nonatomic, assign)CGFloat keyboardHeight;

@end

@implementation M_PhotoDetailViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [self data];
    
}
- (BOOL)prefersStatusBarHidden
{
    return YES;
    
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    // Do any additional setup after loading the view.
}
- (void)data{
    
    self.dataArr = [NSMutableArray array];

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    [productParams setValue:@"1" forKey:@"page"];
    
    //    [productParams setValue:@"10" forKey:@"pagesize"];
    NSString *type = [NSString stringWithFormat:@"%ld", (long)self.albumid];
    [productParams setValue:type forKey:@"albumid"];
    
    [[MNetworkHandler sharedInstance]conURL:selimages networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"Status"]intValue]==200) {
            
            self.dataArr = returnData[@"Data"];
            NSLog(@"%@", self.dataArr);
            
            
            
            
            [self creationView];
            [self creationHeadView];
            [self creationFootView];
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"Msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
    
}
- (void)creationView{
    
    
    self.sxssScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, (KIsiPhoneX?0:0), DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    [self.view addSubview:self.sxssScrollView];
 self.sxssScrollView.contentSize=CGSizeMake(DEF_SCREEN_WIDTH*self.dataArr.count,DEF_SCREEN_HEIGHT);
    if (@available(iOS 11.0, *)) {
        self.sxssScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    self.sxssScrollView.backgroundColor=[UIColor whiteColor];
    self.sxssScrollView.showsHorizontalScrollIndicator=NO;
    self.sxssScrollView.pagingEnabled = YES;
    self.sxssScrollView.delegate = self;
    
    
    
    // [self.sxssScrollView removeAllSubviews];
    
    for (int i=0; i<self.dataArr.count; i++) {
        
        UIImageView *picImageView=[[UIImageView alloc]initWithFrame:CGRectMake(DEF_SCREEN_WIDTH*i, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
        
        //        picImageView.image = [UIImage imageNamed:@"p_cover"];
        
        [picImageView sd_setImageWithURL:[NSURL URLWithString:[self.dataArr[i] objectForKey:@"albumimage"]] placeholderImage:[UIImage imageNamed:@"p_cover"]];
        
        picImageView.contentMode = UIViewContentModeScaleAspectFill;
        picImageView.clipsToBounds = YES;
        picImageView.userInteractionEnabled = YES;
       
        
        
        
        UIButton *buttonOfShool=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
        
        [buttonOfShool addTarget:self action:@selector(myBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        buttonOfShool.tag = i;
        
        [self.sxssScrollView addSubview:picImageView];
        
        
       
   
        [picImageView addSubview:buttonOfShool];
    }
    
}

///////
- (void) scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    
    //1.根据偏移量判断一下应该显示第几个item
    CGFloat offSetX = targetContentOffset->x;
    
    //item的宽度+行间距 = 页码的宽度
    NSInteger pageWidth = DEF_SCREEN_WIDTH;
    
    //根据偏移量计算是第几页
    NSInteger pageNum = (offSetX+pageWidth/2)/pageWidth + 1;
    
    //2.根据显示的第几个item，从而改变偏移量
//    targetContentOffset->x = pageNum*pageWidth;
    
    self.numLab.text = [NSString stringWithFormat:@"%ld/%lu", (long)pageNum,(unsigned long)self.dataArr.count];
    
}
#pragma mark ---------- 添加上面view
- (void)creationHeadView{
    
    self.headrView = [[UIView alloc] init];
    [self.view addSubview:self.headrView];
    self.headrView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, (KIsiPhoneX?64:44));
    self.headrView.backgroundColor = [UIColor whiteColor];
    self.headrView.hidden = YES;
    
    UIImage *backImg = [UIImage imageNamed:@"icon_return_p"];
    UIButton *backBtn = [[UIButton alloc] init];
    [self.headrView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headrView).with.offset(-10);
        make.left.equalTo(self.headrView).with.offset(14);
        make.width.offset(backImg.size.width);
        make.height.offset(backImg.size.height);
    }];
    [backBtn setBackgroundImage:backImg forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.numLab = [[UILabel alloc] init];
    [self.headrView addSubview:self.numLab];
    [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headrView);
        make.centerY.equalTo(backBtn);
        
        
    }];
    self.numLab.textColor = getColor(@"ff40c6");
    self.numLab.font = [UIFont systemFontOfSize:17];
    self.numLab.text = [NSString stringWithFormat:@"1/%lu", (unsigned long)self.dataArr.count];

    
    
    self.headBtn = [[UIButton alloc] init];
    [self.headrView addSubview:self.headBtn];
//    UIImage *head = [UIImage imageNamed:self.headImg];
    [self.headBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.headrView).with.offset(-12);
        make.centerY.equalTo(backBtn);
        make.width.offset(22);
        make.height.offset(22);
        
    }];
//    [self.headBtn setBackgroundImage:head forState:UIControlStateNormal];
    
    [self.headBtn sd_setImageWithURL:[NSURL URLWithString:self.headImg] forState:UIControlStateNormal];
    self.headBtn.layer.cornerRadius = 11;
    self.headBtn.layer.masksToBounds = YES;
    
    
    [self.headBtn addTarget:self action:@selector(mineClick) forControlEvents:UIControlEventTouchUpInside];
    
    
}
- (void)yanZhengSC{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    
    NSString *type = [NSString stringWithFormat:@"%ld", (long)self.albumid];
    [productParams setValue:type forKey:@"albumid"];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:checkcollect networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"Status"]intValue]==200) {
            
            if ([returnData[@"Data"] intValue] == 1) {
                //
                [self.collectionBtn setImage:[UIImage imageNamed:@"icon_collection_p"] forState:UIControlStateNormal];
                
            }else{
                
                [self.collectionBtn setImage:[UIImage imageNamed:@"icon_collection"] forState:UIControlStateNormal];
            }
            
            
        }else{
            
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"Msg"] duration:5.0f];
            //            [hud removeFromSuperview];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        //        [hud removeFromSuperview];
    }];
}
#pragma mark ----------   添加下面view
- (void)creationFootView{
    
    
    [self yanZhengSC];
    
    
    
    self.footView = [[UIView alloc] init];
    [self.view addSubview:self.footView];
    self.footView.frame = CGRectMake(0, DEF_SCREEN_HEIGHT-50, DEF_SCREEN_WIDTH, 50);
    self.footView.backgroundColor = [UIColor whiteColor];
    self.footView.hidden = YES;

    _fenXiangBtn = [[UIButton alloc] init];
    UIImage *fenXiangImg = [UIImage imageNamed:@"icon_share"];
    [self.footView addSubview:_fenXiangBtn];
    [_fenXiangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.footView).with.offset(-20);
        make.centerY.equalTo(self.footView);
        make.width.offset(fenXiangImg.size.width);
        make.height.offset(fenXiangImg.size.height);
    }];
    [_fenXiangBtn setBackgroundImage:fenXiangImg forState:UIControlStateNormal];
    [_fenXiangBtn addTarget:self action:@selector(fenXiangClick) forControlEvents:UIControlEventTouchUpInside];
    
    _fenXiangBtn.hidden = NO;
    self.collectionBtn = [[UIButton alloc] init];
    self.collectionBtn.hidden = NO;
    UIImage *collectionImg = [UIImage imageNamed:@"icon_collection"];
    [self.footView addSubview:_collectionBtn];
    [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.fenXiangBtn.mas_left).with.offset(-30);
        make.centerY.equalTo(self.footView);
        make.width.offset(collectionImg.size.width);
        make.height.offset(collectionImg.size.height);
    }];
//    [_collectionBtn setBackgroundImage:collectionImg forState:UIControlStateNormal];
    [_collectionBtn addTarget:self action:@selector(collectionClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    self.commentBtn = [[UIButton alloc] init];
    self.commentBtn.hidden = NO;
    UIImage *commentImg = [UIImage imageNamed:@"icon_comment"];
    [self.footView addSubview:self.commentBtn];
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.collectionBtn.mas_left).with.offset(-30);
        make.centerY.equalTo(self.footView);
        make.width.offset(commentImg.size.width);
        make.height.offset(commentImg.size.height);
    }];
    [self.commentBtn setBackgroundImage:commentImg forState:UIControlStateNormal];
    [self.commentBtn addTarget:self action:@selector(commentButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    //互动
    _commentView = [[UIView alloc] init];
    [self.footView addSubview:_commentView];
    [_commentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.footView).with.offset(20);
        make.right.equalTo(self.commentBtn.mas_left).with.offset(-20);
        make.height.offset(30);
        make.centerY.equalTo(self.footView);
        
    }];
    _commentView.backgroundColor = [UIColor whiteColor];
    _commentView.layer.borderColor = getColor(@"b7b7b7").CGColor;
    _commentView.layer.borderWidth = 1.0f;
    _commentView.layer.cornerRadius = 15;
    _commentView.layer.masksToBounds = YES;
    _commentView.hidden = NO;
    /////写评论
    self.commentTF = [[UITextView alloc] init];
    [self.footView addSubview:self.commentTF];
    self.commentTF.frame=CGRectMake(32, 15, DEF_SCREEN_WIDTH - 200, 20);
    self.commentTF.delegate = self;
    self.commentTF.font = [UIFont systemFontOfSize:15];
    
    
    //键盘的frame即将发生变化时立刻发出该通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
    
    
    self.faSongBtn = [[UIButton alloc] init];
    [self.footView addSubview:self.faSongBtn];
    [self.faSongBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.footView).with.offset(-12);
        make.bottom.equalTo(self.footView).with.offset(-10);
        make.height.offset(30);
        
    }];
    [self.faSongBtn setBackgroundImage:[UIImage imageNamed:@"bg_send"] forState:UIControlStateNormal];
    [self.faSongBtn setTitle:@"发送" forState:UIControlStateNormal];
    self.faSongBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.faSongBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.faSongBtn.hidden = YES;
    
     [self.faSongBtn addTarget:self action:@selector(fasongClick) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark ------------   收藏 --------------------------------
- (void)collectionClick{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *type = [NSString stringWithFormat:@"%ld", (long)self.albumid];
    [productParams setValue:type forKey:@"albumid"];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:collect networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"Status"]intValue]==200) {
            
            [self yanZhengSC];
            
            
            
//             [PublicFunction showAlert:nil message:@"收藏成功" duration:5.0f];
            
            
        }else{
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"Msg"] duration:5.0f];
            //            [hud removeFromSuperview];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        //        [hud removeFromSuperview];
    }];
    
    
}
#pragma mark ------------ 发送 --------------------------------
- (void)fasongClick{
    
    if (self.commentTF.text.length == 0) {
//        [PublicFunction showAlert:nil message:@"评论不能为空" duration:5.0f];
        return;
    }
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *type = [NSString stringWithFormat:@"%ld", (long)self.albumid];
    [productParams setValue:type forKey:@"albumid"];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:self.commentTF.text forKey:@"content"];
    [[MNetworkHandler sharedInstance]conURL:setcomment networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"Status"]intValue]==200) {
            
            [self.commentTF resignFirstResponder];
            M_PhotoHuDongViewController *vc = [[M_PhotoHuDongViewController alloc] init];
            vc.albumid = self.albumid;
            
            [self.navigationController pushViewController:vc animated:YES];
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"Msg"] duration:5.0f];
            //            [hud removeFromSuperview];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        //        [hud removeFromSuperview];
    }];

    

}

// 开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView{
    NSLog(@"3333333333333");
    self.commentView.hidden = YES;
    _fenXiangBtn.hidden = YES;
    self.collectionBtn.hidden = YES;
    self.commentBtn.hidden = YES;
    self.faSongBtn.hidden = NO;
    self.commentTF.frame=CGRectMake(12, 15, DEF_SCREEN_WIDTH - 80, 20);
    
    
}
// 结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView{
    NSLog(@"55555555555555");
//    self.faSongBtn.hidden = YES;
//    self.commentBtn.hidden = NO;
//    self.commentView.hidden = NO;
//    _fenXiangBtn.hidden = NO;
//    self.collectionBtn.hidden = NO;
//    self.commentTF.frame=CGRectMake(32, 15, DEF_SCREEN_WIDTH - 200, 20);
}
-(void)keyboardChanged:(NSNotification *)notification{
    
    NSLog(@"%@",notification);
    //键盘即将消失的字典
    NSDictionary *willDisAppeardic=@{@"name":@"UIKeyboardWillChangeFrameNotification",
                                     @"userInfo": @{
                                             
                                             @"UIKeyboardAnimationCurveUserInfoKey" : @7,
                                             //键盘离开或进入屏幕的时间
                                             @"UIKeyboardAnimationDurationUserInfoKey": @"0.25",
                                             //键盘大小
                                             @"UIKeyboardBoundsUserInfoKey" : @"NSRect: {{0, 0}, {414, 311}}",
                                             @"UIKeyboardCenterBeginUserInfoKey" : @"NSPoint: {207, 580.5}",
                                             @"UIKeyboardCenterEndUserInfoKey" : @"NSPoint: {207, 891.5}",
                                             //键盘位置改变前的frame
                                             @"UIKeyboardFrameBeginUserInfoKey" : @"NSRect: {{0, 425}, {414, 311}}",
                                             //键盘位置改变后的frame
                                             @"UIKeyboardFrameEndUserInfoKey" : @"NSRect: {{0, 736}, {414, 311}}",
                                             @"UIKeyboardIsLocalUserInfoKey" : @1
                                             }
                                     };
    //键盘即将展示的字典
    NSDictionary *willAppeardic=@{@"name":@"UIKeyboardWillChangeFrameNotification",
                                  @"userInfo": @{
                                          
                                          @"UIKeyboardAnimationCurveUserInfoKey" : @7,
                                          @"UIKeyboardAnimationDurationUserInfoKey": @"0.25",
                                          @"UIKeyboardBoundsUserInfoKey" : @"NSRect: {{0, 0}, {414, 266}}",
                                          @"UIKeyboardCenterBeginUserInfoKey" : @"NSPoint: {207, 869}",
                                          @"UIKeyboardCenterEndUserInfoKey" : @"NSPoint: {207, 603}",
                                          @"UIKeyboardFrameBeginUserInfoKey" : @"NSRect: {{0, 736}, {414, 266}}",
                                          @"UIKeyboardFrameEndUserInfoKey" : @"NSRect: {{0, 470}, {414, 266}}",
                                          @"UIKeyboardIsLocalUserInfoKey" : @1
                                          }
                                  };
    
    CGRect frame=[notification.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
    
    CGRect currentFrame=self.footView.frame;
    
    [UIView animateWithDuration:0.25 animations:^{
        //输入框最终的位置
        CGRect resultFrame;
        
        if (frame.origin.y==DEF_SCREEN_HEIGHT) {
            resultFrame=CGRectMake(currentFrame.origin.x, DEF_SCREEN_HEIGHT-currentFrame.size.height-(KIsiPhoneX?35:0), currentFrame.size.width, currentFrame.size.height);
            self.keyboardHeight=0;
            self.faSongBtn.hidden = YES;
            self.commentBtn.hidden = NO;
            self.commentView.hidden = NO;
            self.fenXiangBtn.hidden = NO;
            self.collectionBtn.hidden = NO;
            self.commentTF.frame=CGRectMake(32, 15, DEF_SCREEN_WIDTH - 200, 20);
            self.footView.frame = CGRectMake(0, DEF_SCREEN_HEIGHT-50, DEF_SCREEN_WIDTH, 50);
            self.commentTF.text = @"";

        }else{
            resultFrame=CGRectMake(currentFrame.origin.x,DEF_SCREEN_HEIGHT-currentFrame.size.height-frame.size.height, currentFrame.size.width, currentFrame.size.height);
            self.keyboardHeight=frame.size.height;
            self.footView.frame=resultFrame;
        }
        
    }];
    
}

-(void)textViewDidChange:(UITextView *)textView{
    
    NSString *str=textView.text;
    
    CGSize maxSize=CGSizeMake(textView.bounds.size.width, MAXFLOAT);
    //NSStringDrawingUsesLineFragmentOrigin:用于多行绘制，因为默认是单行绘制，如果不指定，那么绘制出来的高度就是0，也就是啥都不显示出来。
    
    //NSStringDrawingUsesFontLeading:计算行高时使用自体的间距，也就是行高=行距+字体高度
    
    //NSStringDrawingUsesDeviceMetrics:计算布局时使用图元字形（而不是印刷字体）
    
    //NSStringDrawingTruncatesLastVisibleLine:设置的string的bounds放不下文本的话，就会截断，然后在最后一个可见行后面加上省略号。如果NSStringDrawingUsesLineFragmentOrigin不设置的话，只设置这一个选项是会被忽略的。因为如果不设置NSStringDrawingUsesLineFragmentOrigin，默认是单行显示的。
    //(注意：我在弹出框的内容string中设置了这个字串，但是最后显示出来的时候并没有打省略号…,这是因为在当前方法boundingRectWithSize..中设置这个option并不会起作用的，因为当前方法只是测量string的大小，并不是绘制string，在drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:...这个方法中设置这个option就会起作用)
    
    
    //测量string的大小
    CGRect frame=[str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:textView.font} context:nil];
    //设置self.textView的高度，默认是30
    CGFloat tarHeight=30;
    //如果文本框内容的高度+10大于30也就是初始的self.textview的高度的话，设置tarheight的大小为文本的内容+10，其中10是文本框和背景view的上下间距；
    if (frame.size.height+10>30) {
        tarHeight=frame.size.height+10;
    }
    //如果self.textView的高度大于200时，设置为200，即最高位200
    if (tarHeight>200) {
        tarHeight=200;
    }
    
    CGFloat width=DEF_SCREEN_WIDTH;
    //设置输入框背景的frame
    self.footView.frame=CGRectMake(0, (DEF_SCREEN_HEIGHT-self.keyboardHeight)-(tarHeight+20), width, tarHeight+20);
    //设置输入框的frame
    self.commentTF.frame=CGRectMake(15,(self.footView.bounds.size.height-tarHeight)/2 , width-30-50, tarHeight);
}
#pragma mark ------------ 点击图片
- (void)myBtnClick:(UIButton *)sender{
    
    sender.selected =!sender.selected;
    if (sender.selected) {
        NSLog(@"1");
        self.sxssScrollView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT);
        self.headrView.hidden = NO;
        self.footView.hidden = NO;
    }else{
        NSLog(@"2");
        self.sxssScrollView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT);
        
        [self.commentTF resignFirstResponder];
        self.headrView.hidden = YES;
        self.footView.hidden = YES;
    }
    
    
}
#pragma mark -----------返回
- (void)backClick{
    [self.commentTF resignFirstResponder];
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

#pragma mark ------------ 个人详情

- (void)mineClick{
    [self.commentTF resignFirstResponder];
    M_PhotoMineDetailViewController *vc = [[M_PhotoMineDetailViewController alloc] init];
    vc.modelId = self.modelId;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}
#pragma mark ------------ 互动
- (void)commentButtonClick{
    [self.commentTF resignFirstResponder];
    M_PhotoHuDongViewController *vc = [[M_PhotoHuDongViewController alloc] init];
    vc.albumid = self.albumid;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark ----------------分享
- (void)fenXiangClick{
    

    grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    grayView.backgroundColor = [UIColor colorWithRed:0 / 255.0f green:0 / 255.0f blue:0 / 255.0f alpha:0.2];
    
    [[UIApplication sharedApplication].keyWindow addSubview:grayView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
    [grayView addGestureRecognizer:tapGesture];
    UIView *changeView = [[UIView alloc] init];
    [grayView addSubview:changeView];
    [changeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(160);
        
    }];
    changeView.backgroundColor = getColor(@"f7f7f7");
    changeView.layer.cornerRadius = 5;
    changeView.layer.masksToBounds = YES;
    ////诶下==微信
    UIButton *weiXinBtn = [[UIButton alloc] init];
    [changeView addSubview:weiXinBtn];
    [weiXinBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(changeView).with.offset(16);
        make.width.offset(50);
        make.height.offset(50);
        make.left.offset((DEF_SCREEN_WIDTH - 150)/4);
    }];
    [weiXinBtn setImage:[UIImage imageNamed:@"icon_wechat_p"] forState:UIControlStateNormal];
    [weiXinBtn addTarget:self action:@selector(weiXinClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *weiXinLab = [[UILabel alloc] init];
    [changeView addSubview:weiXinLab];
    [weiXinLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weiXinBtn.mas_bottom).with.offset(5);
        make.centerX.equalTo(weiXinBtn);
        
        
    }];
    weiXinLab.text = @"微信";
    weiXinLab.textColor = getColor(@"818181");
    weiXinLab.font = [UIFont systemFontOfSize:14];
    //
    UIButton *kongJianBtn = [[UIButton alloc] init];
    [changeView addSubview:kongJianBtn];
    [kongJianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(changeView).with.offset(16);
        make.width.offset(50);
        make.height.offset(50);
        make.left.equalTo(weiXinBtn.mas_right).offset((DEF_SCREEN_WIDTH - 150)/4);
    }];
    [kongJianBtn setImage:[UIImage imageNamed:@"icon_circle"] forState:UIControlStateNormal];
    [kongJianBtn addTarget:self action:@selector(pengYouQuan) forControlEvents:UIControlEventTouchUpInside];
    UILabel *kongJianLab = [[UILabel alloc] init];
    [changeView addSubview:kongJianLab];
    [kongJianLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(kongJianBtn.mas_bottom).with.offset(5);
        make.centerX.equalTo(kongJianBtn);
        
        
    }];
    kongJianLab.text = @"朋友圈";
    kongJianLab.textColor = getColor(@"818181");
    kongJianLab.font = [UIFont systemFontOfSize:14];

    UIButton *cancelBtn = [[UIButton alloc] init];
    [changeView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(weiXinBtn.mas_bottom).with.offset(30);
    }];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [cancelBtn setTitleColor:getColor(@"818181") forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.backgroundColor = [UIColor whiteColor];
    cancelBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    cancelBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
    
    
}

- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType
{
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    //    NSString* thumbURL =  @"";
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:self.name descr:@"潘多拉盒" thumImage:[UIImage imageNamed:@"icon-1024"]];
    
    //设置网页地址
    shareObject.webpageUrl = Share;
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
  
            
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        
    }];
    
}
- (void)dismissContactView {
    [grayView removeFromSuperview];
}
/////////微信
- (void)weiXinClick{
    
    [self shareTextToPlatformType:UMSocialPlatformType_WechatSession];
    
    
}
- (void)pengYouQuan{
    [self shareTextToPlatformType:UMSocialPlatformType_WechatTimeLine];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
